package com.esp.soccertutor.animation;

import android.view.View;
import android.view.animation.DecelerateInterpolator;

public final class SwapViews implements Runnable {
	private boolean mIsFirstView;
	View scroll1;
	View scroll2;

	public SwapViews(boolean isFirstView, View textScroll1, View textScroll2) {
		mIsFirstView = isFirstView;
		this.scroll1 = textScroll1;
		this.scroll2 = textScroll2;
	}

	public void run() {
		final float centerX = scroll1.getWidth() / 2.0f;
		final float centerY = scroll1.getHeight() / 2.0f;
		Flip3dAnimation rotation;

		if (mIsFirstView) {
			scroll1.setVisibility(View.GONE);
			scroll2.setVisibility(View.VISIBLE);
			scroll2.requestFocus();

			rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
		} else {
			scroll2.setVisibility(View.GONE);
			scroll1.setVisibility(View.VISIBLE);
			scroll1.requestFocus();

			rotation = new Flip3dAnimation(90, 0, centerX, centerY);
		}

		rotation.setDuration(500);
		rotation.setFillAfter(true);
		rotation.setInterpolator(new DecelerateInterpolator());

		if (mIsFirstView) {
			scroll2.startAnimation(rotation);
		} else {
			scroll1.startAnimation(rotation);
		}
	}
}